import { Router } from 'express';

import { validateBody, validateParams, validateQuery } from '../../middleware/validation';
import { addProjectScript, addProjectScriptSchema } from './add-script';
import { create, del } from './api';
import { deleteProjectScript, deleteProjectScriptParamsSchema } from './delete-script';
import { listProjects, listProjectsSchema } from './list';

const router = Router();

// 获取项目列表 GET:/api/project
router.get('/', validateQuery(listProjectsSchema), listProjects);

// 创建项目 POST:/api/project
router.post('/', validateBody(create.validator), create.api);

// 删除项目 DELETE:/api/project/:id
router.delete('/:id', validateParams(del.validator), del.api);

// 添加项目脚本 POST:/api/project/script
router.post('/script', validateBody(addProjectScriptSchema), addProjectScript);

// 删除项目脚本组 DELETE:/api/project/script-group/:id/:title
router.delete(
  '/script-group/:id/:title',
  validateParams(deleteProjectScriptParamsSchema),
  deleteProjectScript,
);

export default router;
